﻿using CodeFinder.Common;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace CodeFinder.Web.Helper {
    public static class DataHelper {
        private static IList<EnumModel> m_categories;
        private static IList<EnumModel> m_viewscopes; 
        public static IList<EnumModel> GetAllCategories() {
            if (m_categories == null) {
                m_categories = GetEnumModel<CategoryType>();
            }

            return m_categories;
        }

        public static IList<EnumModel> GetAllViewScopes() {
            if (m_viewscopes == null) {
                m_viewscopes = GetEnumModel<ViewScope>();
            }

            return m_viewscopes;
        } 
        private static IList<EnumModel> GetEnumModel<T>() {
            var result = new List<EnumModel>();
            var values = Enum.GetValues(typeof(T));
            foreach (var value in values) {
                T tmp = (T)value;
                dynamic v = (int) value;
                result.Add(new EnumModel() { Id = v, DisplayText = tmp.ToString() });
            }
            return result;
        } 
    }
    public class EnumModel {
        public int Id { get; set; }
        public string DisplayText { get; set; }
    }
}